package com.dotflat.physicalevaluate.domain.pe;

import com.dotflat.physicalevaluate.domain.importexport.PhysicEvaluateImportRecord;
import com.dotflat.rest.domain.AreableObjectBase;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 测量标准
 */
@Data
@Entity
@Table(name = "pe_measure_record")
@EqualsAndHashCode(callSuper = false)
public class PERecord extends AreableObjectBase implements Serializable {

    @Column(columnDefinition = " varchar(10) DEFAULT 'normal' COMMENT '测评模式' ")
    private String evaluateType;

    @Column(columnDefinition = " varchar(32) COMMENT '宝宝id' ")
    private String childrenId;


    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "importRecordId", columnDefinition = " varchar(32) COMMENT '导入记录 id' ")
    @JsonIgnore
    private PhysicEvaluateImportRecord importRecord;
//    @Column(columnDefinition = " varchar(32) COMMENT '导入记录 id' ")
//    private String importRecordId;

    @Column(columnDefinition = " varchar(50) COMMENT '宝宝名称' ")
    private String childrenName;

    @Column(columnDefinition = " int DEFAULT 0 COMMENT '性别 0：女 1：男' ")
    private Integer gender = 0;

    @Column(columnDefinition = " datetime COMMENT '宝宝生日' ")
    private Date birthday;

    @Column(columnDefinition = " int DEFAULT 0 COMMENT '月龄' ")
    private Integer month = 0;

    @Column(columnDefinition = " int DEFAULT 1 COMMENT '状态 1：未评估，2：已归档' ")
    private Integer status = 1;

    @Column(columnDefinition = " varchar(500) COMMENT '总体评估及建议' ")
    private String advise;

    @Column(columnDefinition = " varchar(32) COMMENT '创建老师id' ")
    private String createTeacherId;

    @Column(columnDefinition = " varchar(50) COMMENT '创建老师名称' ")
    private String createTeacherName;

//    @Column(columnDefinition = " varchar(32) COMMENT '机构id' ")
//    private String orgId;

    @Column(columnDefinition = "varchar(5) default '' COMMENT '评估报告分级' ")
    private String rating;

    @Column(columnDefinition = "int DEFAULT 0 COMMENT '发育商' ")
    private int dq;

    @Column(columnDefinition = "int DEFAULT 0 COMMENT '总操作时间，单位秒' ")
    private Long duration;

    @Column(columnDefinition = " datetime COMMENT '评估时间' ")
    private Date evaluatingDate;

    @Column(columnDefinition = " int DEFAULT 0 COMMENT '记录类型 1：签约前初评，2，签约后测评' ")
    private Integer category = 0;

    //测评是不是已经完成了所有维度的填写
    @Column(columnDefinition = " bit DEFAULT 0 COMMENT '状态 false：未完成，true：已完成' ")
    private Boolean finished = false;

    @Column(columnDefinition = " bit DEFAULT 0 COMMENT '是否购买状态 0：否，1是' ")
    private Boolean paid = false;

    @Column(columnDefinition = " bit DEFAULT 0 COMMENT '家长启用 0：否，1是' ")
    private Boolean parentGranted = false;

    //测评发布状态
    @Column(columnDefinition = " bit DEFAULT 0 COMMENT '状态 false：未发布，true：已发布' ")
    private Boolean published = false;

    @Column(columnDefinition = " varchar(200) COMMENT '需要跳过的维度' ")
    private String skipDiemnsions;


    @Column(columnDefinition = " varchar(20) COMMENT '体重' ")
    private String weight;

    @Column(columnDefinition = " varchar(20) COMMENT '身高' ")
    private String height;

    @Column(columnDefinition = " varchar(20) COMMENT '头围' ")
    private String header;

//    @ManyToMany(fetch = FetchType.EAGER)
//    @JoinTable(name = "pe_rel_measure_record",
//            joinColumns = { @JoinColumn(name = "recordId") },
//            inverseJoinColumns = {@JoinColumn(name = "measureId") },
//            foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT),
//            inverseForeignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))


    @OneToMany(mappedBy = "record", cascade = CascadeType.DETACH, fetch = FetchType.EAGER)
    @OrderBy("seq asc")
    private List<RelRecordMeasure> rels;

}